/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_httpd.htm
 *
 * Zhiqim Httpd is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.httpd.websocket;


/**
 * Websocket接口定义
 *
 * @version v1.0.0 @author zouzhigang 2017-6-9 新建与整理
 */
public interface HttpWebSocketService
{
    /**
     * 设置WebSocket所在的管理器
     * 
     * @param manager   WS管理器
     */
    public void setWebSocketManager(HttpWebSocketManager manager);
    
    /**
     * 接收到连接开启
     * 
     * @param conn      WS连接
     */
    public void onOpen(HttpWebSocket conn);
    
    /**
     * 接收连接主动关闭
     * 
     * @param conn      WS连接
     * @param code      关闭代码
     */
    public void onClose(HttpWebSocket conn, int code);
    
    /**
     * 接收异常
     * 
     * @param conn      WS连接
     * @param e         消息异常
     */
    public void onException(HttpWebSocket conn, Throwable e);
    
    /**
     * 接收到PING消息，框架会自动回PONG，业务侧无需回PONG，仅用于跟踪调试
     * 
     * @param conn      WS连接
     */
    public void onPing(HttpWebSocket conn);
    
    /**
     * 接收到PONG消息
     * 
     * @param conn      WS连接
     */
    public void onPong(HttpWebSocket conn);
    
    /**
     * 接收到文本消息
     * 
     * @param conn      WS连接
     * @param text      文本包
     */
    public void onText(HttpWebSocket conn, String text);
    
    /**
     * 接收到二进制包
     * 
     * @param conn      WS连接
     * @param binary    二进制包
     */
    public void onBinary(HttpWebSocket conn, byte[] binary);
    
    /**
     * 接收到中间包
     * 
     * @param conn      WS连接
     * @param middle    中间包字节数组
     */
    public void onMiddle(HttpWebSocket conn, byte[] middle);
    
    /**
     * 接收到自定义的其他消息
     * 
     * @param conn      WS连接
     * @param message   其他消息
     */
    public void onOther(HttpWebSocket conn, byte[] message);
}
